#!/usr/bin/perl

# $Id: 14_filesystem_crawler.t 234 2010-07-13 11:20:23Z dolbanavt $
# $Date: 2010-07-13 14:20:32 +0300 (Вто, 13 Июл 2010) $
# $HeadURL: https://robosearch.googlecode.com/svn/branches/reborn/t/14_filesystem_crawler.t $
# $LastChangedRevision$

use FindBin qw( $RealBin );
use File::Spec::Functions qw( catfile );

BEGIN {
    push @INC, catfile( $RealBin, '..', 'base_lib' );
    push @INC, catfile( $RealBin, '..', 'lib' );
}

use JIP::ToolSet;
use English qw( -no_match_vars );
use Test::More 0.88;
use Const::Fast qw( const );
use Test::MockObject;
use Test::Exception;

const my $MODULE => 'Filesystem::Crawler';

use_ok $MODULE;
require_ok $MODULE;

can_ok $MODULE, qw(
    new _init
    get_host set_host
    get_scratch_dir set_scratch_dir
    get_output_dir set_output_dir
    scratch_file
    scratch_file_location
    output_file
    output_file_location
);

throws_ok { $MODULE->new(); }
    qr{^Required\soption\s'host_object'\sis\snot\sprovided}xms,
    'new( host_object )';

throws_ok { $MODULE->new( host_object => q{} ); }
    qr{^Required\soption\s'scratch_dir'\sis\snot\sprovided}xms,
    'new( scratch_dir )';

throws_ok { $MODULE->new( host_object => q{}, scratch_dir => q{} ); }
    qr{^Required\soption\s'output_dir'\sis\snot\sprovided}xms,
    'new( output_dir )';

my $mock = Test::MockObject->new();

$mock->fake_module( 'Host',
    new            => sub { return bless {}, 'Host' },
    get_id         => sub { return 42; },
    get_ip_address => sub { return '10.0.14.140'; },
);

my $o = $MODULE->new(
    host_object => Host->new(),
    scratch_dir => './tratata_scratch',
    output_dir  => './tratata_output',
);

ok $o, 'got object';

isa_ok $o, $MODULE;
isa_ok $o, 'Filesystem';
isa_ok $o, 'JIP::BaseClass';
isa_ok $o, 'Class::Accessor::Fast';

is ref $o->get_host,    'Host',              'host accessor';
is $o->get_scratch_dir, './tratata_scratch', 'scratch_dir accessor';
is $o->get_output_dir,  './tratata_output',  'output_dir accessor';

is $o->scratch_file(),
   'ftp_crawler.42.yaml.tmp',
   'scratch_file()';

is $o->scratch_file_location(),
   'tratata_scratch/ftp_crawler.42.yaml.tmp',
   'scratch_file_location()';

is $o->output_file(),
   'ftp_crawler.42.yaml',
   'output_file()';

is $o->output_file_location(),
   'tratata_output/ftp_crawler.42.yaml',
   'output_file_location()';

done_testing();
